import { Injectable } from '@angular/core';
import { User } from '../models';

@Injectable({
  providedIn: 'root'
})
export class UserService {

  get user(): User {
    const data = localStorage.getItem('userInfo');
    if (!data) {
      return null;
    }
    return JSON.parse(data);
  }

  set user(user: User) {
    const data = JSON.stringify(user);
    localStorage.setItem('userInfo', data);
  }

  get account() {
    const data = localStorage.getItem('account');
    if (!data) {
      return null;
    }
    return JSON.parse(data) as Account;
  }

  set account(account: Account) {
    const data = JSON.stringify(account);
    localStorage.setItem('account', data);
  }

}
